import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_syt/api/EncryptUtils.dart';
import 'package:flutter_syt/utils/utils_dlog.dart';
import 'package:intl/intl.dart';
import 'package:flutter_syt/api/api.dart';
import 'package:flutter_syt/application.dart';
import 'package:flutter_syt/datas/provider_index_setting.dart';
import 'package:flutter_syt/datas/user_info.dart';
import 'package:flutter_syt/domain/home/share_api.dart';
import 'package:flutter_syt/domain/main_page.dart';
import 'package:flutter_syt/domain/mine/role_box.dart';
import 'package:flutter_syt/domain/mine/signin_page.dart';
import 'package:flutter_syt/domain/widgets/common_dialog.dart';
import 'package:flutter_syt/domain/widgets/custom_dialog.dart';
import 'package:flutter_syt/domain/widgets/list_item.dart';
import 'package:flutter_syt/domain/widgets/pdf_screen.dart';
import 'package:flutter_syt/domain/widgets/person_info_card.dart';
import 'package:flutter_syt/domain/widgets/stupid_title_bar.dart';
import 'package:flutter_syt/generated/l10n.dart';
import 'package:flutter_syt/global_common.dart';
import 'package:flutter_syt/routes.all.dart';
import 'package:flutter_syt/theme/theme_color.dart';
import 'package:flutter_syt/utils/click_utils.dart';
import 'package:flutter_syt/utils/image_picker_helper.dart';
import 'package:flutter_syt/widgets/web_detail.dart';
import 'package:flutter_syt/widgets/web_video_page.dart';
import 'package:provider/provider.dart';
import 'package:yyy_route_annotation/yyy_route_annotation.dart';

import '../../global_easy_loading.dart';

class BoxItemEntity {
  late String text;
  late String imageUrl;
  late GestureTapCallback? onTap;

  BoxItemEntity(this.text, this.imageUrl, this.onTap);
}

class ChooseItemData {
  late String id;
  late String name;

  ChooseItemData(this.id, this.name);
}

@RoutePage(name: "mine_page")
class MinePage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => _MinePageState();
}

class _MinePageState extends State<MinePage> {
  bool isLogin = UserInfo.me.isLogin;

  // 用户基本信息
  PersonInfoEntity? userInfo;

  // List<RoleItemData> roleArr = [];
  // List<RoleItemData> myRoleArr = [];
  List lauguageArr = [
    ChooseItemData('1', S().language_zh),
    ChooseItemData('2', 'English'),
    // ChooseItemData('3', 'Français'),
  ];
  String selectName = S().language_zh;
  String selectId = '1';

  // List<String> qrWhiteList = [];
  GlobalKey _userInfokey = GlobalKey();
  GlobalKey _userUnLoginkey = GlobalKey();
  List _sysTemBatch = [];

  // String? _titile;
  double _userInfoHeight = 0.0;
  List _feedbackModule = [];
  late VoidCallback _call;

  @override
  void dispose() {
    UserInfo.me.removeListener(_call);
    super.dispose();
  }

  @override
  void initState() {
    _call = () {
      var user = UserInfo.me;
      if (UserInfo.me.isLogin) {
        PersonInfoEntity userData = PersonInfoEntity(
          user.nickname,
          '200',
          user.avatar,
          user.roles,
          '铂金',
          '8',
          '1.5',
        );
        if (mounted) {
          setState(() {
            isLogin = UserInfo.me.isLogin;
            userInfo = userData;
          });
        }
      } else {
        if (mounted) {
          setState(() {
            isLogin = UserInfo.me.isLogin;
          });
        }
      }
    };
    UserInfo.me.addListener(_call);
    if (UserInfo.me.isLogin) {
      if (!appContext.isLoadUser) {
        appContext.setLoadUser();
        getUserInfo();
      }
      // getQRWhiteList();
    }
    // getSysTemBatch();
    queryWeather();
    var local = Intl.getCurrentLocale();
    debugPrint("mine local -- $local");
    if (local == "zh") {
      selectId = "1";
      selectName = S().language_zh;
    } else if (local == "en") {
      selectId = "2";
      selectName = "English";
    }

    // WidgetsBinding.instance.addPostFrameCallback((duration) {
    //   RenderObject? box = _userInfokey.currentContext?.findRenderObject();
    //   // _key1.currentContext.size; Size(200.0, 100.0)
    //   if (_userInfoHeight != box?.semanticBounds.size.height) {
    //     if (mounted) {
    //       setState(() {
    //         _userInfoHeight = box?.semanticBounds.size.height ?? 0;
    //       });
    //     }
    //   }
    //   DLog(
    //       "aksjhdfkajsdj   ${box?.semanticBounds.size.height}"); // Size(200.0, 100.0)
    //   // print(box.localToGlobal(Offset.zero)); // Offset(107.0, 100.0)
    // });
    getSysTemBatch();
    super.initState();
  }

  Future getSysTemBatch() async {
    var list = await API.shared.common.getSysTemBatch(
        keys: ['feedback_setting', 'feedback_scene_copywriting']);
    if (list is List) {
      _sysTemBatch = list;
    }
  }

  // Future getQRWhiteList() async {
  //   var list = await API.shared.common.qrWhiteList();
  //   qrWhiteList = list;
  // }

  Future getUserInfo() async {
    await API.shared.user.getUserInfo();
  }

  updataUserHeight() async {
    await Future.delayed(Duration(milliseconds: 50));
    if (isLogin) {
      RenderObject? box = _userInfokey.currentContext?.findRenderObject();
      // _key1.currentContext.size; Size(200.0, 100.0)
      if (_userInfoHeight != box?.semanticBounds.size.height) {
        if (mounted) {
          setState(() {
            _userInfoHeight = box?.semanticBounds.size.height ?? 0;
          });
        }
      }
    } else {
      if (_userInfoHeight != 95.w) {
        if (mounted) {
          setState(() {
            _userInfoHeight = 95.w;
          });
        }
      }
    }
  }

  @override
  Widget build(BuildContext context) {
    updataUserHeight();
    // DLog('dalskjd    ${'13248258731'.sm4}');
    // DLog('dalskjd    ${'eBzY0w0oC4wW5Z5Z4RLqVA=='.deSm4}');
    // var zhLang = true;
    // var local =
    //     appContext.storage.getString("storyLocal") ?? Intl.getCurrentLocale();
    // if (local.contains('zh')) {
    //   zhLang = true;
    // } else {
    //   zhLang = false;
    // }
    return Scaffold(
      body: Container(
          color: Color(0xffF8F8F8),
          // height: double.infinity,
          width: double.infinity,
          child:
              Consumer<ProviderIndexSetting>(builder: (context, value, child) {
            return Stack(
              children: [
                Positioned.fill(
                    child: SingleChildScrollView(
                  child: Stack(
                    children: [
                      Positioned(
                          child: Image.asset(
                        'assets/images/mine_top_bg.png',
                        width: double.infinity,
                        fit: BoxFit.fitWidth,
                        height: 44 +
                            28.w +
                            _userInfoHeight +
                            ScreenUtil().statusBarHeight,
                        alignment: Alignment.bottomCenter,
                      )),
                      Positioned(
                          child: Container(
                              // height: 1.sh,
                              // color: Colors.amber,
                              padding: EdgeInsets.only(
                                  top: ScreenUtil().statusBarHeight + 44),
                              width: MediaQuery.of(context).size.width,
                              child: Column(
                                mainAxisSize: MainAxisSize.min,
                                children: [
                                  Container(
                                    alignment: Alignment.centerLeft,
                                    // height: 136.w,
                                    child: isLogin
                                        ? userInfoView()
                                        // ? (zhLang
                                        //     ? zhUserInfo()
                                        //     : enUserInfo())
                                        : _unLoginBox(),
                                    // child: Column(
                                    //   mainAxisAlignment:
                                    //       MainAxisAlignment.center,
                                    //   children: [
                                    //     isLogin
                                    //         ? userInfoView()
                                    //         // ? (zhLang
                                    //         //     ? zhUserInfo()
                                    //         //     : enUserInfo())
                                    //         : _unLoginBox()
                                    //   ],
                                    // ),
                                  ),
                                  // SizedBox(height: isLogin ? 30 : 12),
                                  // SizedBox(
                                  // height: 30,
                                  // ),
                                  _littleBox(value),
                                  _listContainer(value),
                                  // _otherContainer(),
                                  // GestureDetector(
                                  //   onTap: () {
                                  //     Clipboard.setData(ClipboardData(
                                  //         text: UserInfo.me.token));
                                  //   },
                                  //   child: Text(
                                  //     "usertoken: ${UserInfo.me.token}",
                                  //   ),
                                  // ),
                                  // 12.verticalSpaceFromWidth,
                                  // GestureDetector(
                                  //   onTap: () {
                                  //     appContext.storage
                                  //         .getString("devicTokenID");
                                  //     Clipboard.setData(ClipboardData(
                                  //         text: appContext.storage
                                  //                 .getString("devicTokenID") ??
                                  //             ''));
                                  //   },
                                  //   child: Text(
                                  //     "devicTokenID: ${appContext.storage.getString("devicTokenID")}",
                                  //   ),
                                  // )
                                ],
                              )))
                    ],
                  ),
                )),
                Positioned(
                  top: ScreenUtil().statusBarHeight,
                  child: ColorsTitleBar(
                    weatherEntity,
                    type: BarType.SETTING,
                    isShowWeather: false,
                    isShowService: value.indexSetting.service == 1,
                    // title: S.current.my_account,
                  ),
                )
              ],
            );
          })
          // Stack(
          //   children: [
          //     Positioned(
          //         child: Image.asset(
          //       'assets/images/mine_top_bg.png',
          //       width: double.infinity,
          //       fit: BoxFit.fitWidth,
          //       height: 200 + ScreenUtil().statusBarHeight,
          //       alignment: Alignment.bottomCenter,
          //     )),

          // Container(
          //   child: SafeArea(child: Consumer<ProviderIndexSetting>(
          //       builder: (context, value, child) {
          //     return Container(
          //         // padding: EdgeInsets.only(top: 20),
          //         width: MediaQuery.of(context).size.width,
          //         child: Column(
          //           children: [
          //             ColorsTitleBar(
          //               weatherEntity,
          //               type: BarType.SETTING,
          //               isShowWeather: false,
          //               isShowService: value.indexSetting.service == 1,
          //               // title: S.current.my_account,
          //             ),
          //             Expanded(
          //               child: ListView(
          //                 physics: BouncingScrollPhysics(),
          //                 children: [
          //                   SizedBox(
          //                     height: 124,
          //                     child: Column(
          //                       mainAxisAlignment: MainAxisAlignment.center,
          //                       children: [
          //                         isLogin
          //                             ? (zhLang ? zhUserInfo() : enUserInfo())
          //                             : _unLoginBox()
          //                       ],
          //                     ),
          //                   ),
          //                   // SizedBox(height: isLogin ? 30 : 12),
          //                   // SizedBox(
          //                   // height: 30,
          //                   // ),
          //                   _littleBox(value),
          //                   _listContainer(value),
          //                   // _otherContainer(),
          //                 ],
          //               ),
          //             )
          //           ],
          //         ));
          //   })),
          // ),
          // ],
          ),
      // ),
    );
  }

  // Widget _personInfo() {
  //   var entity = UserInfo.me;
  //   var content = GestureDetector(
  //     onTap: ClickUtils.debounce(() {
  //       RouteManager.push(context, RoutMapping.editUserInfoPage());
  //     }),
  //     child: Container(
  //       padding: EdgeInsets.fromLTRB(10, 0, 10, 0),
  //       child: Column(
  //         children: [
  //           Row(
  //             children: [
  //               Stack(
  //                 children: [
  //                   Container(
  //                     margin: EdgeInsets.only(right: 14, left: 5),
  //                     width: 60,
  //                     height: 60,
  //                     child: CircleAvatar(
  //                       radius: 60,
  //                       backgroundImage: NetworkImage(entity.avatar),
  //                       backgroundColor: Colors.grey,
  //                     ),
  //                   ),
  //                 ],
  //               ),
  //               Expanded(
  //                 child: Column(
  //                   crossAxisAlignment: CrossAxisAlignment.start,
  //                   children: [
  //                     Row(
  //                       children: [
  //                         Flexible(
  //                             child: Text(
  //                           S.of(context).user_nickname,
  //                           textAlign: TextAlign.left,
  //                           style: FontStyles.headerTextStyle_24,
  //                           softWrap: false,
  //                           overflow: TextOverflow.ellipsis,
  //                           // maxLines: 2,
  //                         )),
  //                         SizedBox(width: 12),
  //                         Image.asset(
  //                           "assets/icons/icon_user_edit.png",
  //                           width: 11,
  //                           height: 14,
  //                         ),
  //                       ],
  //                     ),
  //                     Row(
  //                       children: entity.roles
  //                           .map(
  //                             (e) => Container(
  //                               margin: EdgeInsets.only(top: 5, right: 5),
  //                               padding: EdgeInsets.only(left: 5, right: 5),
  //                               alignment: Alignment.center,
  //                               height: 18,
  //                               decoration: BoxDecoration(
  //                                 gradient: LinearGradient(
  //                                   colors: [
  //                                     Color(0xffFFCE00),
  //                                     Color(0xffFF9900),
  //                                   ],
  //                                 ),
  //                                 borderRadius: BorderRadius.circular(8),
  //                               ),
  //                               child: Text(
  //                                 e.name,
  //                                 style: TextStyle(
  //                                   fontSize: 10,
  //                                   color: ThemeColor.bkColorFFFFFF,
  //                                 ),
  //                               ),
  //                             ),
  //                           )
  //                           .toList(),
  //                     )
  //                   ],
  //                 ),
  //               ),
  //               // Spacer(),
  //             ],
  //           ),
  //           SizedBox(height: 10),
  //           Container(
  //             decoration: BoxDecoration(
  //               borderRadius: BorderRadius.circular(8),
  //               color: Color(0xffFFF2CB),
  //             ),
  //             padding: EdgeInsets.symmetric(horizontal: 12, vertical: 5),
  //             child: Row(
  //               children: [
  //                 Expanded(
  //                   child: getTitle(),
  //                 ),
  //               ],
  //             ),
  //           ),
  //         ],
  //       ),
  //     ),
  //   );
  //   return Container(
  //     padding: EdgeInsets.only(top: 10, bottom: 10),
  //     margin: EdgeInsets.fromLTRB(10, 20, 10, 0),
  //     decoration: BoxDecoration(
  //       borderRadius: BorderRadius.circular(12),
  //       color: ThemeColor.bkColorFFFFFF,
  //     ),
  //     child: content,
  //   );
  // }

  Widget userInfoView() {
    var entity = UserInfo.me;
    return Container(
      key: _userInfokey,
      padding: EdgeInsets.symmetric(horizontal: 15, vertical: 20.w),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          Container(
              constraints: BoxConstraints(maxWidth: 220.w),
              child: Text(
                entity.roles.isEmpty
                    ? S.of(context).user_nickname
                    : entity.roles.first.name,
                textAlign: TextAlign.left,
                style: TextStyle(
                    color: ThemeColor.colorBlack100,
                    fontFamily: ' PingFang SC',
                    fontSize: 20.sp,
                    fontWeight: FontWeight.w600),
                softWrap: false,
                overflow: TextOverflow.ellipsis,
                maxLines: 2,
              )
              //   // padding: EdgeInsets.only(top: 25),
              //   child: Row(
              //     crossAxisAlignment: CrossAxisAlignment.end,
              //     children: userList,
              //   ),
              ),
          Padding(
              padding: EdgeInsets.only(left: 23),
              child: Image.asset(
                'assets/icons/mine_login_top_arrow.png',
                width: 13.w,
                height: 6.w,
              )),
          Container(
            // margin: EdgeInsets.only(top: 10),
            decoration: BoxDecoration(
              color: Color(0xffFFF8D1),
              borderRadius: BorderRadius.all(Radius.circular(8)),
            ),
            child: Padding(padding: EdgeInsets.all(8), child: getTitle()),
          ),
        ],
      ),
      // Positioned(
      //   child: Padding(
      //       padding: EdgeInsets.only(left: 23),
      //       child: Image.asset(
      //         'assets/icons/mine_login_top_arrow.png',
      //         width: 13,
      //         height: 6,
      //       )),
      //   top: 58,
      // ),
      // ],
      // ),
    );
    // return Container();
  }

  Widget zhUserInfo() {
    var entity = UserInfo.me;
    List<Widget> userList = [];
    if (entity.roles.isEmpty) {
      userList = [
        Flexible(
            child: Text(
          S.of(context).user_nickname,
          textAlign: TextAlign.left,
          style: TextStyle(
              color: ThemeColor.colorBlack100,
              fontFamily: ' PingFang SC',
              fontSize: 20.sp,
              fontWeight: FontWeight.w600),
          softWrap: false,
          overflow: TextOverflow.ellipsis,
          // maxLines: 2,
        ))
      ];
    } else {
      var roleWidget = entity.roles
          .map(
            (e) => Container(
              padding: EdgeInsets.only(left: 5, right: 5, bottom: 2),
              alignment: Alignment.bottomLeft,
              child: Text(
                e.name,
                style: TextStyle(
                  fontSize: 14,
                  color: ThemeColor.colorBlack60,
                ),
              ),
            ),
          )
          .toList();
      userList = [
        Flexible(
            child: Text(
          entity.cert.name,
          textAlign: TextAlign.left,
          style: TextStyle(
              color: ThemeColor.colorBlack100,
              fontFamily: ' PingFang SC',
              fontSize: 20,
              fontWeight: FontWeight.w600),
          softWrap: false,
          overflow: TextOverflow.ellipsis,
          // maxLines: 2,
        )),
        SizedBox(
          width: 3,
        )
      ];
      userList.addAll(roleWidget);
    }

    return Container(
      padding: EdgeInsets.symmetric(horizontal: 15),
      child: Stack(
        children: [
          Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Container(
                padding: EdgeInsets.only(top: 25),
                child: Row(
                  crossAxisAlignment: CrossAxisAlignment.end,
                  children: userList,
                ),
              ),
              Container(
                margin: EdgeInsets.only(top: 10),
                decoration: BoxDecoration(
                  color: Color(0xffFFF8D1),
                  borderRadius: BorderRadius.all(Radius.circular(8)),
                ),
                child: Padding(padding: EdgeInsets.all(8), child: getTitle()),
              ),
            ],
          ),
          Positioned(
            child: Padding(
                padding: EdgeInsets.only(left: 23),
                child: Image.asset(
                  'assets/icons/mine_login_top_arrow.png',
                  width: 13,
                  height: 6,
                )),
            top: 58,
          ),
        ],
      ),
    );
  }

  Widget enUserInfo() {
    var entity = UserInfo.me;
    List<Widget> userList = [];
    if (entity.roles.isEmpty) {
      userList = [
        Row(
          children: [
            Flexible(
                child: Text(
              S.of(context).user_nickname,
              textAlign: TextAlign.left,
              style: TextStyle(
                  color: ThemeColor.colorBlack100,
                  fontFamily: ' PingFang SC',
                  fontSize: 20,
                  fontWeight: FontWeight.w600),
              softWrap: false,
              overflow: TextOverflow.ellipsis,
              // maxLines: 2,
            ))
          ],
        )
      ];
    } else {
      List<Widget> roleWidgets = [];
      for (int i = 0; i < entity.roles.length; i++) {
        var item = entity.roles[i];
        var content = Container(
          padding: EdgeInsets.only(left: i == 0 ? 0 : 5, right: 5, bottom: 2),
          alignment: Alignment.bottomLeft,
          child: Text(
            item.name,
            style: TextStyle(
              fontSize: 14,
              color: ThemeColor.colorBlack60,
            ),
          ),
        );
        roleWidgets.add(content);
      }
      userList = [
        Row(
          children: [
            Flexible(
                child: Text(
              entity.name,
              textAlign: TextAlign.left,
              style: TextStyle(
                  color: ThemeColor.colorBlack100,
                  fontFamily: ' PingFang SC',
                  fontSize: 20,
                  fontWeight: FontWeight.w600),
              softWrap: false,
              overflow: TextOverflow.ellipsis,
              // maxLines: 2,
            )),
          ],
        )
        // SizedBox(width: 3,)
      ];
      userList.addAll(roleWidgets);
    }

    return Container(
      padding: EdgeInsets.symmetric(horizontal: 15),
      child: Stack(
        children: [
          Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Padding(
                padding: EdgeInsets.only(top: 25),
                child: Column(
                  children: userList,
                ),
              ),
              Padding(
                  padding: EdgeInsets.only(left: 23),
                  child: Image.asset(
                    'assets/icons/mine_login_top_arrow.png',
                    width: 13,
                    height: 6,
                  )),
              Container(
                decoration: BoxDecoration(
                  color: Color(0xffFFF8D1),
                  borderRadius: BorderRadius.all(Radius.circular(8)),
                ),
                child: Padding(padding: EdgeInsets.all(8), child: getTitle()),
              ),
            ],
          ),
        ],
      ),
    );
  }

  RichText getTitle() {
    var local =
        appContext.storage.getString("storyLocal") ?? Intl.getCurrentLocale();
    var str = S.of(context).user_brief_1;
    var str2 = S.of(context).user_brief_2;
    // var no = '';
    // if (local.contains('zh')) {
    //   no = "${UserInfo.me.id - 10000000}";
    // } else {
    //   no = "${UserInfo.me.id - 10000000}";
    // }
    return RichText(
      textAlign: TextAlign.left,
      text: TextSpan(
        children: [
          TextSpan(
            text: str + ' ',
            style: (TextStyle(
              fontWeight: FontWeight.w400,
              fontSize: 12,
              color: Colors.black,
            )),
          ),
          TextSpan(
            text: UserInfo.me.serial_number.toString(),
            style: (TextStyle(
              fontWeight: FontWeight.w400,
              fontSize: 12,
              color: Color(0xffF6A220),
            )),
          ),
          TextSpan(
            text: ' ' + str2,
            style: (TextStyle(
              fontWeight: FontWeight.w400,
              fontSize: 12,
              color: Colors.black,
            )),
          ),
        ],
      ),
    );
  }

  Widget _littleBox(ProviderIndexSetting indexProvider) {
    List<BoxItemEntity> boxList = [];
    if (indexProvider.indexSetting.shop == 1) {
      boxList.add(BoxItemEntity(
        S.of(context).mall,
        "assets/icons/icon_sale.png",
        () async {
          if (appContext.provider.userMallUrl.isEmpty) {
            customShowToast(S().standy_by);
          } else {
            if (UserInfo.me.isLogin) {
              var web = WebDetailPage(GlobalData.mallMine());
              // web.needLongpressSave = false;
              Navigator.of(context).push(MaterialPageRoute(
                  builder: (context) => web,
                  settings: RouteSettings(name: "mine_page", arguments: "")));
            } else {
              // Navigator.of(context).push(MaterialPageRoute(
              //     builder: (context) => web,
              //     settings: RouteSettings(name: "mine_page", arguments: "")));
              RouteManager.push(
                context,
                RoutMapping.loginByPwd(),
              );
            }
          }
        },
      ));
    }
    if (indexProvider.indexSetting.signIn == 1) {
      boxList.add(BoxItemEntity(
        S.of(context).sign_in,
        "assets/icons/icon_sign.png",
        () {
          // customShowToast(S().standy_by);
          if (UserInfo.me.isLogin) {
            Navigator.of(context)
                .push(MaterialPageRoute(builder: (context) => SignInPage()));
          } else {
            RouteManager.push(
              context,
              RoutMapping.loginByPwd(),
            );
          }
        },
      ));
    }

    if (indexProvider.indexSetting.feedBack == 1) {
      boxList.add(BoxItemEntity(
        S.of(context).feedback_title,
        "assets/images/mine_feedBack.png",
        () async {
          if (!isLogin) {
            RouteManager.push(
              context,
              RoutMapping.loginByPwd(),
            );
            return;
          }

          if (_feedbackModule.isEmpty) {
            Future getFeedbackModule() async {
              _feedbackModule = await API.shared.feedback.feedbackModule();
            }

            await loading(getFeedbackModule);
          }

          if (_feedbackModule.length <= 1) {
            RouteManager.push(
              context,
              RoutMapping.feedbackPage(
                _feedbackModule.isEmpty ? 1 : _feedbackModule.first['id'],
              ),
            );
          } else {
            {
              if (_sysTemBatch.isEmpty) {
                await getSysTemBatch();
              }
              String? titile;
              _sysTemBatch.forEach((element) {
                if (element['key'] == 'feedback_scene_copywriting') {
                  var local = appContext.storage.getString("storyLocal") ??
                      Intl.getCurrentLocale();
                  Map map = jsonDecode(element['value']);
                  if (local.contains('zh')) {
                    titile = map['zh'];
                  } else {
                    titile = map['en'];
                  }
                }
              });
              var result = await DialogHelper.showFeedbackBottom(
                context, _feedbackModule,
                title: titile,
                // (value) {
                //   RouteManager.push(
                //       context,
                //       RoutMapping.feedbackPage(
                //         value['id'],
                //       ));
                // }
              );
              if (result is Map) {
                RouteManager.push(
                    context,
                    RoutMapping.feedbackPage(
                      result['id'],
                    ));
                //                         _module = result;
                // checkDataSource();
              }
            }
          }
        },
      ));
    }

    boxList.add(BoxItemEntity(
      S.of(context).MyMessages,
      "assets/images/mine_messages.png",
      () async {
        if (!UserInfo.me.isLogin) {
          RouteManager.push(
            context,
            RoutMapping.loginByPwd(),
          );
          return;
        }
        RouteManager.push(context, RoutMapping.message());
      },
    ));

    return Container(
      height: 101,
      // width: 80.w,
      padding: EdgeInsets.symmetric(horizontal: 10.w, vertical: 15),
      margin: EdgeInsets.fromLTRB(15.w, 0, 15.w, 0),
      decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(12),
        color: ThemeColor.bkColorFFFFFF,
        // color: Colors.red
      ),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceAround,
        children: boxList
            .map((e) => GestureDetector(
                  onTap: e.onTap,
                  child: Container(
                      width: 80.w,
                      // color: Colors.blueGrey,
                      alignment: Alignment.center,
                      child: _iconText(e.imageUrl, e.text)),
                ))
            .toList(),
      ),
    );
  }

  Widget _iconText(String url, String text) {
    return Column(
      mainAxisSize: MainAxisSize.min,
      children: [
        Image.asset(
          url,
          width: 38,
          height: 38,
        ),
        Container(
          margin: EdgeInsets.only(top: 6),
          child: Text(
            text,
            maxLines: 1,
            style: TextStyle(
              fontSize: 12,
              color: ThemeColor.colorBlack100,
              // fontWeight: FontWeight.w300,
            ),
          ),
        ),
      ],
    );
  }

  Widget _listContainer(ProviderIndexSetting value) {
    return Container(
      // margin: EdgeInsets.all,
      margin: EdgeInsets.fromLTRB(15.w, 10.w, 15.w, 0),
      decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(12),
        color: ThemeColor.bkColorFFFFFF,
        // border: Border.all(
        //   color: Color(0xffeeeeee),
        //   width: 0.5,
        //   style: BorderStyle.solid,
        // ),
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
        children: _getRowsList(value)
            .map((e) => GestureDetector(
                  onTap: ClickUtils.debounce(() => e.onTap),
                  child: Container(
                      // color: Colors.blueGrey,
                      alignment: Alignment.center,
                      child: ListItem(e)),
                ))
            .toList(),
      ),
    );
  }

  // Widget _otherContainer() {
  //   List<ListItemEntity> listData = [
  //     ListItemEntity(
  //       S.of(context).feedback,
  //       "assets/images/opinionImg.png",
  //       '',
  //       () => {},
  //     ),
  //     ListItemEntity(
  //       S.of(context).MyMessages,
  //       "assets/images/cameraImg.png",
  //       '',
  //       () async {
  //         //TODO:扫码
  //         // var result = await Navigator.of(this.context).push(
  //         //   MaterialPageRoute(
  //         //     builder: (context) => QRCodePage(),
  //         //   ),
  //         // );
  //         RouteManager.push(context, RoutMapping.message());
  //       },
  //       isShowBorder: false,
  //     ),
  //   ];

  //   return Container(
  //     margin: EdgeInsets.fromLTRB(10, 0, 10, 10),
  //     decoration: BoxDecoration(
  //       borderRadius: BorderRadius.circular(12),
  //       color: ThemeColor.bkColorFFFFFF,
  //       border: Border.all(
  //         color: Color(0xffeeeeee),
  //         width: 0.5,
  //         style: BorderStyle.solid,
  //       ),
  //     ),
  //     child: Column(
  //       crossAxisAlignment: CrossAxisAlignment.start,
  //       mainAxisAlignment: MainAxisAlignment.spaceEvenly,
  //       children: listData
  //           .map((e) => GestureDetector(
  //                 onTap: e.onTap,
  //                 child: Container(
  //                     // color: Colors.blueGrey,
  //                     alignment: Alignment.center,
  //                     child: ListItem(e)),
  //               ))
  //           .toList(),
  //     ),
  //   );
  // }

  Widget _unLoginBox() {
    return GestureDetector(
      key: _userUnLoginkey,
      onTap: ClickUtils.debounce(() {
        RouteManager.push(
          context,
          RoutMapping.loginByPwd(),
        );
      }),
      child: Container(
        height: 95.w,
        child: Row(
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            Container(
              padding: EdgeInsets.only(left: 15),
              child: Row(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text(
                    S.of(context).log_in_sign_up,
                    style: TextStyle(
                      color: ThemeColor.colorBlack100,
                      fontSize: 20,
                      fontWeight: FontWeight.bold,
                    ),
                  ),
                ],
              ),
            ),
            Spacer(),
          ],
        ),
      ),
    );
  }

  List<ListItemEntity> _getRowsList(ProviderIndexSetting indexProvider) {
    RoleItemEntity laugaugeData = RoleItemEntity(
      lauguageArr,
      (id, name) {
        selectId = id;
        selectName = name;
      },
      role: selectName,
    );
    List<ListItemEntity> rowsList = [];
    //积分
    if (indexProvider.indexSetting.integral == 1) {
      rowsList.add(ListItemEntity(
        S.of(context).points,
        "assets/icons/icon_score.png",
        '',
        () {
          // customShowToast(S().standy_by);
          if (appContext.provider.userPointUrl.isEmpty) {
            customShowToast(S().standy_by);
          } else {
            if (UserInfo.me.isLogin) {
              // Navigator.of(context).push(MaterialPageRoute(
              //     builder: (ctx) =>
              //         WebProtocolDetailPage(appContext.provider.userPointUrl)));
              var web = WebDetailPage(GlobalData.userPointUrl());
              // web.needLongpressSave = false;
              Navigator.of(context).push(MaterialPageRoute(
                  builder: (context) => web,
                  settings: RouteSettings(name: "mine_page", arguments: "")));
            } else {
              RouteManager.push(
                context,
                RoutMapping.loginByPwd(),
              );
            }
          }
        },
      ));
    }
//身份认证
    if ((UserInfo.me.cert.license_number == 'null' ||
            UserInfo.me.cert.license_number == '') &&
        indexProvider.indexSetting.authentication == 1) {
      rowsList.add(ListItemEntity(
          S.of(context).verify_identity, "assets/images/roleImg.png", '', () {
        if (!isLogin) {
          RouteManager.push(
            context,
            RoutMapping.loginByPwd(),
          );
          return;
        }
        if (UserInfo.me.cert.license_number == 'null' ||
            UserInfo.me.cert.license_number == '') {
          RouteManager.push(
            context,
            RoutMapping.authenticationForm(),
          );
        } else {
          RouteManager.push(
            context,
            RoutMapping.authenticationForm(id: '1'),
          );
        }
      }));
    }

    //我的活动
    if (indexProvider.indexSetting.activity == 1) {
      rowsList.add(
        ListItemEntity(
          S.of(context).activities,
          "assets/images/activityImg.png",
          '',
          () {
            // customShowToast(S().standy_by);
            if (UserInfo.me.isLogin) {
              // Navigator.of(context).push(MaterialPageRoute(
              //     builder: (ctx) =>
              //         WebProtocolDetailPage(GlobalData.activityMine())));
              var web = WebDetailPage(GlobalData.activityMine());
              // web.needLongpressSave = false;
              Navigator.of(context).push(MaterialPageRoute(
                  builder: (context) => web,
                  settings: RouteSettings(name: "mine_page", arguments: "")));
            } else {
              RouteManager.push(
                context,
                RoutMapping.loginByPwd(),
              );
            }
          },
        ),
      );
    }
    rowsList.add(
      ListItemEntity(
        S.of(context).languages,
        "assets/images/languageImg.png",
        '',
        () {
          // DLog('msg');
          // ProviderIndexSetting indexSettingProvider =
          //     Provider.of<ProviderIndexSetting>(context, listen: false);
          // IndexSetting indexSetting = ProviderIndexSetting().indexSetting;
          // indexSetting.gameSchedule = 0;
          // indexSettingProvider.indexSetting = indexSetting;

          showCommonDialog(
            context,
            DialogEntity(
              S.of(context).Languages,

              RoleBox(laugaugeData),
              () {
                Navigator.of(context).pop();
              },
              () async {
                await Navigator.of(context).maybePop();
                String? local;
                if (selectId == "1") {
                  local = "zh";
                } else if (selectId == "2") {
                  local = "en";
                } else if (selectId == "3") {
                  local = "fr";
                }
                if (local != null) {
                  S.delegate.load(Locale(local));
                  appContext.storage.setString("storyLocal", local);
                  if (UserInfo.me.isLogin) {
                    await API.shared.user.updateUserInfo('lang', local);
                  }
                }
                Navigator.of(context).pushReplacement(
                  MaterialPageRoute(
                    builder: (context) {
                      return MainPage();
                    },
                  ),
                );
              },
              // contentPadding: EdgeInsets.zero,
              cancelText: S.of(context).cancel,

              okText: S.of(context).Save,
            ),
          );
        },
        isShowBorder: (indexProvider.indexSetting.opManual == 1 ||
            indexProvider.indexSetting.opManual == 1),
      ),
    );
    if (indexProvider.indexSetting.opManual == 1) {
      //操作手册
      rowsList.add(
        ListItemEntity(
          S.of(context).mine_opManual,
          "assets/icons/icon_manual.png",
          '',
          () {
            var local = appContext.storage.getString("storyLocal") ??
                Intl.getCurrentLocale();

            // var web = WebDetailPage(local.contains('zh')
            //     ? (indexProvider.indexSetting.opManualOptions?.url ?? '')
            //     : (indexProvider.indexSetting.opManualOptions?.urlEn ?? ''));

            Navigator.push(
                context,
                MaterialPageRoute(
                    builder: (context) => PDFScreen(
                          local.contains('zh')
                              ? (indexProvider
                                      .indexSetting.opManualOptions?.url ??
                                  '')
                              : (indexProvider
                                      .indexSetting.opManualOptions?.urlEn ??
                                  ''),
                          title: S.of(context).mine_opManual,
                        )));
          },
          isShowBorder: true,
        ),
      );
    }
    if (indexProvider.indexSetting.opVideo == 1) {
      //操作视频
      rowsList.add(
        ListItemEntity(
          S.of(context).mine_opVideo,
          "assets/icons/icon_video.png",
          '',
          () {
            var local = appContext.storage.getString("storyLocal") ??
                Intl.getCurrentLocale();

            // var web = WebDetailPage(local.contains('zh')
            //     ? (indexProvider.indexSetting.opVideoOptions?.url ?? '')
            //     : (indexProvider.indexSetting.opVideoOptions?.urlEn ?? ''));
            // web.needLongpressSave = false;
            // web.isUseUserAgent = true;
            Navigator.of(context).push(MaterialPageRoute(
                builder: (context) => WebVideoPage(
                      local.contains('zh')
                          ? (indexProvider.indexSetting.opVideoOptions?.url ??
                              '')
                          : (indexProvider.indexSetting.opVideoOptions?.urlEn ??
                              ''),
                      title: S.of(context).mine_opVideo,
                    ),
                settings: RouteSettings(name: "mine_page_web", arguments: "")));
          },
          isShowBorder: false,
        ),
      );
    }
    return rowsList;
  }
}
